package com.company;

import java.util.Random;
// 打乱数组数据
public class RandomArr {
    public static void main(String[] args) {
        // write your code here
//        int[] arr = {1, 2, 3, 4, 5};
//        Random r = new Random();
//        int randomIndex = r.nextInt(arr.length);
//        System.out.println(arr[randomIndex]);

        int[] arr = {1, 2, 3, 4, 5};
        Random rand = new Random();
        for (int i = 0; i < arr.length; i++) {
            int randomIndex = rand.nextInt(arr.length);

            int temp = arr[i];
            arr[i] = arr[randomIndex];
            arr[randomIndex] = temp;
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
